package com.treasure.common.reponse;

import lombok.Data;

import java.io.Serializable;

/**
 * @author sunhongmin
 * @date 2023/8/26 07:57
 * @description
 */
@Data
public class Response<T> implements Serializable {

    /**
     * 响应码 （1xxx 为操作成功）
     */
    private final Integer code;
    /**
     * 响应信息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;

    public Response(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Response(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    public Response(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Response<String> success() {
        return new Response<>(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMessage());
    }

    public static <T> Response<T> success(T data) {
        return new Response<>(ResponseCodeEnum.SUCCESS.getCode(), data);
    }

    public static Response<String> error(ResponseCodeEnum responseCode, String message) {
        return new Response<>(responseCode.getCode(), message);
    }

    public static <T> Response<T> error(ResponseCodeEnum responseCode, String message, T data) {
        return new Response<>(responseCode.getCode(), message, data);
    }

}
